<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>linkdialogplugin.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_editor_plugins_linkdialogplugin.js.html">linkdialogplugin.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview A plugin for the LinkDialog.
<a name="line17"></a> *
<a name="line18"></a> * @author nicksantos@google.com (Nick Santos)
<a name="line19"></a> * @author marcosalmeida@google.com (Marcos Almeida)
<a name="line20"></a> * @author robbyw@google.com (Robby Walker)
<a name="line21"></a> */
<a name="line22"></a>
<a name="line23"></a>goog.provide(&#39;goog.editor.plugins.LinkDialogPlugin&#39;);
<a name="line24"></a>
<a name="line25"></a>goog.require(&#39;goog.array&#39;);
<a name="line26"></a>goog.require(&#39;goog.dom&#39;);
<a name="line27"></a>goog.require(&#39;goog.editor.Command&#39;);
<a name="line28"></a>goog.require(&#39;goog.editor.plugins.AbstractDialogPlugin&#39;);
<a name="line29"></a>goog.require(&#39;goog.events.EventHandler&#39;);
<a name="line30"></a>goog.require(&#39;goog.functions&#39;);
<a name="line31"></a>goog.require(&#39;goog.ui.editor.AbstractDialog.EventType&#39;);
<a name="line32"></a>goog.require(&#39;goog.ui.editor.LinkDialog&#39;);
<a name="line33"></a>goog.require(&#39;goog.ui.editor.LinkDialog.EventType&#39;);
<a name="line34"></a>goog.require(&#39;goog.ui.editor.LinkDialog.OkEvent&#39;);
<a name="line35"></a>goog.require(&#39;goog.uri.utils&#39;);
<a name="line36"></a>
<a name="line37"></a>
<a name="line38"></a>
<a name="line39"></a>/**
<a name="line40"></a> * A plugin that opens the link dialog.
<a name="line41"></a> * @constructor
<a name="line42"></a> * @extends {goog.editor.plugins.AbstractDialogPlugin}
<a name="line43"></a> */
<a name="line44"></a>goog.editor.plugins.LinkDialogPlugin = function() {
<a name="line45"></a>  goog.base(this, goog.editor.Command.MODAL_LINK_EDITOR);
<a name="line46"></a>
<a name="line47"></a>  /**
<a name="line48"></a>   * Event handler for this object.
<a name="line49"></a>   * @type {goog.events.EventHandler}
<a name="line50"></a>   * @private
<a name="line51"></a>   */
<a name="line52"></a>  this.eventHandler_ = new goog.events.EventHandler(this);
<a name="line53"></a>
<a name="line54"></a>
<a name="line55"></a>  /**
<a name="line56"></a>   * A list of whitelisted URL schemes which are safe to open.
<a name="line57"></a>   * @type {Array.&lt;string&gt;}
<a name="line58"></a>   * @private
<a name="line59"></a>   */
<a name="line60"></a>  this.safeToOpenSchemes_ = [&#39;http&#39;, &#39;https&#39;, &#39;ftp&#39;];
<a name="line61"></a>};
<a name="line62"></a>goog.inherits(goog.editor.plugins.LinkDialogPlugin,
<a name="line63"></a>    goog.editor.plugins.AbstractDialogPlugin);
<a name="line64"></a>
<a name="line65"></a>
<a name="line66"></a>/**
<a name="line67"></a> * Link object that the dialog is editing.
<a name="line68"></a> * @type {goog.editor.Link}
<a name="line69"></a> * @protected
<a name="line70"></a> */
<a name="line71"></a>goog.editor.plugins.LinkDialogPlugin.prototype.currentLink_;
<a name="line72"></a>
<a name="line73"></a>
<a name="line74"></a>/**
<a name="line75"></a> * Optional warning to show about email addresses.
<a name="line76"></a> * @type {string|undefined}
<a name="line77"></a> * @private
<a name="line78"></a> */
<a name="line79"></a>goog.editor.plugins.LinkDialogPlugin.prototype.emailWarning_;
<a name="line80"></a>
<a name="line81"></a>
<a name="line82"></a>/**
<a name="line83"></a> * Whether to show a checkbox where the user can choose to have the link open in
<a name="line84"></a> * a new window.
<a name="line85"></a> * @type {boolean}
<a name="line86"></a> * @private
<a name="line87"></a> */
<a name="line88"></a>goog.editor.plugins.LinkDialogPlugin.prototype.showOpenLinkInNewWindow_ = false;
<a name="line89"></a>
<a name="line90"></a>
<a name="line91"></a>/**
<a name="line92"></a> * Whether the &quot;open link in new window&quot; checkbox should be checked when the
<a name="line93"></a> * dialog is shown, and also whether it was checked last time the dialog was
<a name="line94"></a> * closed.
<a name="line95"></a> * @type {boolean}
<a name="line96"></a> * @private
<a name="line97"></a> */
<a name="line98"></a>goog.editor.plugins.LinkDialogPlugin.prototype.isOpenLinkInNewWindowChecked_ =
<a name="line99"></a>    false;
<a name="line100"></a>
<a name="line101"></a>
<a name="line102"></a>/**
<a name="line103"></a> * Weather to show a checkbox where the user can choose to add &#39;rel=nofollow&#39;
<a name="line104"></a> * attribute added to the link.
<a name="line105"></a> * @type {boolean}
<a name="line106"></a> * @private
<a name="line107"></a> */
<a name="line108"></a>goog.editor.plugins.LinkDialogPlugin.prototype.showRelNoFollow_ = false;
<a name="line109"></a>
<a name="line110"></a>
<a name="line111"></a>/**
<a name="line112"></a> * Whether to stop referrer leaks.  Defaults to false.
<a name="line113"></a> * @type {boolean}
<a name="line114"></a> * @private
<a name="line115"></a> */
<a name="line116"></a>goog.editor.plugins.LinkDialogPlugin.prototype.stopReferrerLeaks_ = false;
<a name="line117"></a>
<a name="line118"></a>
<a name="line119"></a>/**
<a name="line120"></a> * Whether to block opening links with a non-whitelisted URL scheme.
<a name="line121"></a> * @type {boolean}
<a name="line122"></a> * @private
<a name="line123"></a> */
<a name="line124"></a>goog.editor.plugins.LinkDialogPlugin.prototype.blockOpeningUnsafeSchemes_ =
<a name="line125"></a>    true;
<a name="line126"></a>
<a name="line127"></a>
<a name="line128"></a>/** @override */
<a name="line129"></a>goog.editor.plugins.LinkDialogPlugin.prototype.getTrogClassId =
<a name="line130"></a>    goog.functions.constant(&#39;LinkDialogPlugin&#39;);
<a name="line131"></a>
<a name="line132"></a>
<a name="line133"></a>/**
<a name="line134"></a> * Tells the plugin whether to block URLs with schemes not in the whitelist.
<a name="line135"></a> * If blocking is enabled, this plugin will stop the &#39;Test Link&#39; popup
<a name="line136"></a> * window from being created. Blocking doesn&#39;t affect link creation--if the
<a name="line137"></a> * user clicks the &#39;OK&#39; button with an unsafe URL, the link will still be
<a name="line138"></a> * created as normal.
<a name="line139"></a> * @param {boolean} blockOpeningUnsafeSchemes Whether to block non-whitelisted
<a name="line140"></a> *     schemes.
<a name="line141"></a> */
<a name="line142"></a>goog.editor.plugins.LinkDialogPlugin.prototype.setBlockOpeningUnsafeSchemes =
<a name="line143"></a>    function(blockOpeningUnsafeSchemes) {
<a name="line144"></a>  this.blockOpeningUnsafeSchemes_ = blockOpeningUnsafeSchemes;
<a name="line145"></a>};
<a name="line146"></a>
<a name="line147"></a>
<a name="line148"></a>/**
<a name="line149"></a> * Sets a whitelist of allowed URL schemes that are safe to open.
<a name="line150"></a> * Schemes should all be in lowercase. If the plugin is set to block opening
<a name="line151"></a> * unsafe schemes, user-entered URLs will be converted to lowercase and checked
<a name="line152"></a> * against this list. The whitelist has no effect if blocking is not enabled.
<a name="line153"></a> * @param {Array.&lt;string&gt;} schemes String array of URL schemes to allow (http,
<a name="line154"></a> *     https, etc.).
<a name="line155"></a> */
<a name="line156"></a>goog.editor.plugins.LinkDialogPlugin.prototype.setSafeToOpenSchemes =
<a name="line157"></a>    function(schemes) {
<a name="line158"></a>  this.safeToOpenSchemes_ = schemes;
<a name="line159"></a>};
<a name="line160"></a>
<a name="line161"></a>
<a name="line162"></a>/**
<a name="line163"></a> * Tells the dialog to show a checkbox where the user can choose to have the
<a name="line164"></a> * link open in a new window.
<a name="line165"></a> * @param {boolean} startChecked Whether to check the checkbox the first
<a name="line166"></a> *     time the dialog is shown. Subesquent times the checkbox will remember its
<a name="line167"></a> *     previous state.
<a name="line168"></a> */
<a name="line169"></a>goog.editor.plugins.LinkDialogPlugin.prototype.showOpenLinkInNewWindow =
<a name="line170"></a>    function(startChecked) {
<a name="line171"></a>  this.showOpenLinkInNewWindow_ = true;
<a name="line172"></a>  this.isOpenLinkInNewWindowChecked_ = startChecked;
<a name="line173"></a>};
<a name="line174"></a>
<a name="line175"></a>
<a name="line176"></a>/**
<a name="line177"></a> * Tells the dialog to show a checkbox where the user can choose to have
<a name="line178"></a> * &#39;rel=nofollow&#39; attribute added to the link.
<a name="line179"></a> */
<a name="line180"></a>goog.editor.plugins.LinkDialogPlugin.prototype.showRelNoFollow = function() {
<a name="line181"></a>  this.showRelNoFollow_ = true;
<a name="line182"></a>};
<a name="line183"></a>
<a name="line184"></a>
<a name="line185"></a>/**
<a name="line186"></a> * Returns whether the&quot;open link in new window&quot; checkbox was checked last time
<a name="line187"></a> * the dialog was closed.
<a name="line188"></a> * @return {boolean} Whether the&quot;open link in new window&quot; checkbox was checked
<a name="line189"></a> *     last time the dialog was closed.
<a name="line190"></a> */
<a name="line191"></a>goog.editor.plugins.LinkDialogPlugin.prototype.
<a name="line192"></a>    getOpenLinkInNewWindowCheckedState = function() {
<a name="line193"></a>  return this.isOpenLinkInNewWindowChecked_;
<a name="line194"></a>};
<a name="line195"></a>
<a name="line196"></a>
<a name="line197"></a>/**
<a name="line198"></a> * Tells the plugin to stop leaking the page&#39;s url via the referrer header when
<a name="line199"></a> * the &quot;test this link&quot; link is clicked. When the user clicks on a link, the
<a name="line200"></a> * browser makes a request for the link url, passing the url of the current page
<a name="line201"></a> * in the request headers. If the user wants the current url to be kept secret
<a name="line202"></a> * (e.g. an unpublished document), the owner of the url that was clicked will
<a name="line203"></a> * see the secret url in the request headers, and it will no longer be a secret.
<a name="line204"></a> * Calling this method will not send a referrer header in the request, just as
<a name="line205"></a> * if the user had opened a blank window and typed the url in themselves.
<a name="line206"></a> */
<a name="line207"></a>goog.editor.plugins.LinkDialogPlugin.prototype.stopReferrerLeaks = function() {
<a name="line208"></a>  this.stopReferrerLeaks_ = true;
<a name="line209"></a>};
<a name="line210"></a>
<a name="line211"></a>
<a name="line212"></a>/**
<a name="line213"></a> * Sets the warning message to show to users about including email addresses on
<a name="line214"></a> * public web pages.
<a name="line215"></a> * @param {string} emailWarning Warning message to show users about including
<a name="line216"></a> *     email addresses on the web.
<a name="line217"></a> */
<a name="line218"></a>goog.editor.plugins.LinkDialogPlugin.prototype.setEmailWarning = function(
<a name="line219"></a>    emailWarning) {
<a name="line220"></a>  this.emailWarning_ = emailWarning;
<a name="line221"></a>};
<a name="line222"></a>
<a name="line223"></a>
<a name="line224"></a>/**
<a name="line225"></a> * Handles execCommand by opening the dialog.
<a name="line226"></a> * @param {string} command The command to execute.
<a name="line227"></a> * @param {*=} opt_arg {@link A goog.editor.Link} object representing the link
<a name="line228"></a> *     being edited.
<a name="line229"></a> * @return {*} Always returns true, indicating the dialog was shown.
<a name="line230"></a> * @protected
<a name="line231"></a> * @override
<a name="line232"></a> */
<a name="line233"></a>goog.editor.plugins.LinkDialogPlugin.prototype.execCommandInternal = function(
<a name="line234"></a>    command, opt_arg) {
<a name="line235"></a>  this.currentLink_ = /** @type {goog.editor.Link} */(opt_arg);
<a name="line236"></a>  return goog.base(this, &#39;execCommandInternal&#39;, command, opt_arg);
<a name="line237"></a>};
<a name="line238"></a>
<a name="line239"></a>
<a name="line240"></a>/**
<a name="line241"></a> * Handles when the dialog closes.
<a name="line242"></a> * @param {goog.events.Event} e The AFTER_HIDE event object.
<a name="line243"></a> * @override
<a name="line244"></a> * @protected
<a name="line245"></a> */
<a name="line246"></a>goog.editor.plugins.LinkDialogPlugin.prototype.handleAfterHide = function(e) {
<a name="line247"></a>  goog.base(this, &#39;handleAfterHide&#39;, e);
<a name="line248"></a>  this.currentLink_ = null;
<a name="line249"></a>};
<a name="line250"></a>
<a name="line251"></a>
<a name="line252"></a>/**
<a name="line253"></a> * @return {goog.events.EventHandler} The event handler.
<a name="line254"></a> * @protected
<a name="line255"></a> */
<a name="line256"></a>goog.editor.plugins.LinkDialogPlugin.prototype.getEventHandler = function() {
<a name="line257"></a>  return this.eventHandler_;
<a name="line258"></a>};
<a name="line259"></a>
<a name="line260"></a>
<a name="line261"></a>/**
<a name="line262"></a> * @return {goog.editor.Link} The link being edited.
<a name="line263"></a> * @protected
<a name="line264"></a> */
<a name="line265"></a>goog.editor.plugins.LinkDialogPlugin.prototype.getCurrentLink = function() {
<a name="line266"></a>  return this.currentLink_;
<a name="line267"></a>};
<a name="line268"></a>
<a name="line269"></a>
<a name="line270"></a>/**
<a name="line271"></a> * Creates a new instance of the dialog and registers for the relevant events.
<a name="line272"></a> * @param {goog.dom.DomHelper} dialogDomHelper The dom helper to be used to
<a name="line273"></a> *     create the dialog.
<a name="line274"></a> * @param {*=} opt_link The target link (should be a goog.editor.Link).
<a name="line275"></a> * @return {goog.ui.editor.LinkDialog} The dialog.
<a name="line276"></a> * @override
<a name="line277"></a> * @protected
<a name="line278"></a> */
<a name="line279"></a>goog.editor.plugins.LinkDialogPlugin.prototype.createDialog = function(
<a name="line280"></a>    dialogDomHelper, opt_link) {
<a name="line281"></a>  var dialog = new goog.ui.editor.LinkDialog(dialogDomHelper,
<a name="line282"></a>      /** @type {goog.editor.Link} */ (opt_link));
<a name="line283"></a>  if (this.emailWarning_) {
<a name="line284"></a>    dialog.setEmailWarning(this.emailWarning_);
<a name="line285"></a>  }
<a name="line286"></a>  if (this.showOpenLinkInNewWindow_) {
<a name="line287"></a>    dialog.showOpenLinkInNewWindow(this.isOpenLinkInNewWindowChecked_);
<a name="line288"></a>  }
<a name="line289"></a>  if (this.showRelNoFollow_) {
<a name="line290"></a>    dialog.showRelNoFollow();
<a name="line291"></a>  }
<a name="line292"></a>  dialog.setStopReferrerLeaks(this.stopReferrerLeaks_);
<a name="line293"></a>  this.eventHandler_.
<a name="line294"></a>      listen(dialog, goog.ui.editor.AbstractDialog.EventType.OK,
<a name="line295"></a>          this.handleOk).
<a name="line296"></a>      listen(dialog, goog.ui.editor.AbstractDialog.EventType.CANCEL,
<a name="line297"></a>          this.handleCancel_).
<a name="line298"></a>      listen(dialog, goog.ui.editor.LinkDialog.EventType.BEFORE_TEST_LINK,
<a name="line299"></a>          this.handleBeforeTestLink);
<a name="line300"></a>  return dialog;
<a name="line301"></a>};
<a name="line302"></a>
<a name="line303"></a>
<a name="line304"></a>/** @override */
<a name="line305"></a>goog.editor.plugins.LinkDialogPlugin.prototype.disposeInternal = function() {
<a name="line306"></a>  goog.base(this, &#39;disposeInternal&#39;);
<a name="line307"></a>  this.eventHandler_.dispose();
<a name="line308"></a>};
<a name="line309"></a>
<a name="line310"></a>
<a name="line311"></a>/**
<a name="line312"></a> * Handles the OK event from the dialog by updating the link in the field.
<a name="line313"></a> * @param {goog.ui.editor.LinkDialog.OkEvent} e OK event object.
<a name="line314"></a> * @protected
<a name="line315"></a> */
<a name="line316"></a>goog.editor.plugins.LinkDialogPlugin.prototype.handleOk = function(e) {
<a name="line317"></a>  // We&#39;re not restoring the original selection, so clear it out.
<a name="line318"></a>  this.disposeOriginalSelection();
<a name="line319"></a>
<a name="line320"></a>  this.currentLink_.setTextAndUrl(e.linkText, e.linkUrl);
<a name="line321"></a>  if (this.showOpenLinkInNewWindow_) {
<a name="line322"></a>    // Save checkbox state for next time.
<a name="line323"></a>    this.isOpenLinkInNewWindowChecked_ = e.openInNewWindow;
<a name="line324"></a>  }
<a name="line325"></a>
<a name="line326"></a>  var anchor = this.currentLink_.getAnchor();
<a name="line327"></a>  this.touchUpAnchorOnOk_(anchor, e);
<a name="line328"></a>  var extraAnchors = this.currentLink_.getExtraAnchors();
<a name="line329"></a>  for (var i = 0; i &lt; extraAnchors.length; ++i) {
<a name="line330"></a>    extraAnchors[i].href = anchor.href;
<a name="line331"></a>    this.touchUpAnchorOnOk_(extraAnchors[i], e);
<a name="line332"></a>  }
<a name="line333"></a>
<a name="line334"></a>  // Place cursor to the right of the modified link.
<a name="line335"></a>  this.currentLink_.placeCursorRightOf();
<a name="line336"></a>
<a name="line337"></a>  this.getFieldObject().focus();
<a name="line338"></a>
<a name="line339"></a>  this.getFieldObject().dispatchSelectionChangeEvent();
<a name="line340"></a>  this.getFieldObject().dispatchChange();
<a name="line341"></a>
<a name="line342"></a>  this.eventHandler_.removeAll();
<a name="line343"></a>};
<a name="line344"></a>
<a name="line345"></a>
<a name="line346"></a>/**
<a name="line347"></a> * Apply the necessary properties to a link upon Ok being clicked in the dialog.
<a name="line348"></a> * @param {HTMLAnchorElement} anchor The anchor to set properties on.
<a name="line349"></a> * @param {goog.events.Event} e Event object.
<a name="line350"></a> * @private
<a name="line351"></a> */
<a name="line352"></a>goog.editor.plugins.LinkDialogPlugin.prototype.touchUpAnchorOnOk_ =
<a name="line353"></a>    function(anchor, e) {
<a name="line354"></a>  if (this.showOpenLinkInNewWindow_) {
<a name="line355"></a>    if (e.openInNewWindow) {
<a name="line356"></a>      anchor.target = &#39;_blank&#39;;
<a name="line357"></a>    } else {
<a name="line358"></a>      if (anchor.target == &#39;_blank&#39;) {
<a name="line359"></a>        anchor.target = &#39;&#39;;
<a name="line360"></a>      }
<a name="line361"></a>      // If user didn&#39;t indicate to open in a new window but the link already
<a name="line362"></a>      // had a target other than &#39;_blank&#39;, let&#39;s leave what they had before.
<a name="line363"></a>    }
<a name="line364"></a>  }
<a name="line365"></a>
<a name="line366"></a>  if (this.showRelNoFollow_) {
<a name="line367"></a>    var alreadyPresent = goog.ui.editor.LinkDialog.hasNoFollow(anchor.rel);
<a name="line368"></a>    if (alreadyPresent &amp;&amp; !e.noFollow) {
<a name="line369"></a>      anchor.rel = goog.ui.editor.LinkDialog.removeNoFollow(anchor.rel);
<a name="line370"></a>    } else if (!alreadyPresent &amp;&amp; e.noFollow) {
<a name="line371"></a>      anchor.rel = anchor.rel ? anchor.rel + &#39; nofollow&#39; : &#39;nofollow&#39;;
<a name="line372"></a>    }
<a name="line373"></a>  }
<a name="line374"></a>};
<a name="line375"></a>
<a name="line376"></a>
<a name="line377"></a>/**
<a name="line378"></a> * Handles the CANCEL event from the dialog by clearing the anchor if needed.
<a name="line379"></a> * @param {goog.events.Event} e Event object.
<a name="line380"></a> * @private
<a name="line381"></a> */
<a name="line382"></a>goog.editor.plugins.LinkDialogPlugin.prototype.handleCancel_ = function(e) {
<a name="line383"></a>  if (this.currentLink_.isNew()) {
<a name="line384"></a>    goog.dom.flattenElement(this.currentLink_.getAnchor());
<a name="line385"></a>    var extraAnchors = this.currentLink_.getExtraAnchors();
<a name="line386"></a>    for (var i = 0; i &lt; extraAnchors.length; ++i) {
<a name="line387"></a>      goog.dom.flattenElement(extraAnchors[i]);
<a name="line388"></a>    }
<a name="line389"></a>    // Make sure listeners know the anchor was flattened out.
<a name="line390"></a>    this.getFieldObject().dispatchChange();
<a name="line391"></a>  }
<a name="line392"></a>
<a name="line393"></a>  this.eventHandler_.removeAll();
<a name="line394"></a>};
<a name="line395"></a>
<a name="line396"></a>
<a name="line397"></a>/**
<a name="line398"></a> * Handles the BeforeTestLink event fired when the &#39;test&#39; link is clicked.
<a name="line399"></a> * @param {goog.ui.editor.LinkDialog.BeforeTestLinkEvent} e BeforeTestLink event
<a name="line400"></a> *     object.
<a name="line401"></a> * @protected
<a name="line402"></a> */
<a name="line403"></a>goog.editor.plugins.LinkDialogPlugin.prototype.handleBeforeTestLink =
<a name="line404"></a>    function(e) {
<a name="line405"></a>  if (!this.shouldOpenUrl(e.url)) {
<a name="line406"></a>    /** @desc Message when the user tries to test (preview) a link, but the
<a name="line407"></a>     * link cannot be tested. */
<a name="line408"></a>    var MSG_UNSAFE_LINK = goog.getMsg(&#39;This link cannot be tested.&#39;);
<a name="line409"></a>    alert(MSG_UNSAFE_LINK);
<a name="line410"></a>    e.preventDefault();
<a name="line411"></a>  }
<a name="line412"></a>};
<a name="line413"></a>
<a name="line414"></a>
<a name="line415"></a>/**
<a name="line416"></a> * Checks whether the plugin should open the given url in a new window.
<a name="line417"></a> * @param {string} url The url to check.
<a name="line418"></a> * @return {boolean} If the plugin should open the given url in a new window.
<a name="line419"></a> * @protected
<a name="line420"></a> */
<a name="line421"></a>goog.editor.plugins.LinkDialogPlugin.prototype.shouldOpenUrl = function(url) {
<a name="line422"></a>  return !this.blockOpeningUnsafeSchemes_ || this.isSafeSchemeToOpen_(url);
<a name="line423"></a>};
<a name="line424"></a>
<a name="line425"></a>
<a name="line426"></a>/**
<a name="line427"></a> * Determines whether or not a url has a scheme which is safe to open.
<a name="line428"></a> * Schemes like javascript are unsafe due to the possibility of XSS.
<a name="line429"></a> * @param {string} url A url.
<a name="line430"></a> * @return {boolean} Whether the url has a safe scheme.
<a name="line431"></a> * @private
<a name="line432"></a> */
<a name="line433"></a>goog.editor.plugins.LinkDialogPlugin.prototype.isSafeSchemeToOpen_ =
<a name="line434"></a>    function(url) {
<a name="line435"></a>  var scheme = goog.uri.utils.getScheme(url) || &#39;http&#39;;
<a name="line436"></a>  return goog.array.contains(this.safeToOpenSchemes_, scheme.toLowerCase());
<a name="line437"></a>};
</pre>


</body>
</html>
